package com.wondersgroup.wuhan_demo.util;

import android.text.TextUtils;

import com.wondersgroup.wuhan_demo.entity.DaoSession;
import com.wondersgroup.wuhan_demo.entity.DeptVo;
import com.wondersgroup.wuhan_demo.entity.DeptVoDao;

import java.util.List;

public class DBUtil {

    private final DaoSession daoSession;

    public DBUtil(DaoSession daoSession) {
        this.daoSession = daoSession;
    }

    public List<DeptVo> loadDepartments(String condition) {
        if (TextUtils.isEmpty(condition)) {
            return daoSession.getDeptVoDao().queryBuilder().build().list();
        } else {
//            QueryBuilder<DeptVo> queryBuilder = daoSession.getDeptVoDao().queryBuilder();
            String keywords = "%" + condition + "%";
            return daoSession.getDeptVoDao().queryBuilder().where(
                    daoSession.getDeptVoDao().queryBuilder().or(
                            DeptVoDao.Properties.DeptName.like(keywords),
                            DeptVoDao.Properties.DeptNamePinyin.like(keywords)
                    )
            ).build().list();
        }
    }

}
